class Solution
{
public:
    void rotate(vector<int>& nums, int k)
    {
        int n = nums.size();
        k = k % n;

        vector<int> ans(n);
        for (int i = 0; i < n; i++)
        {
            ans[(i + k) % n] = nums[i];
        }
        for (int i = 0; i < n; i++)
        {
            nums[i] = ans[i];
        }
    }
};

class Solution
{
public:
    void rotate(vector<int>& nums, int k)
    {
        int n = nums.size();
        k = k % n;

        reverse(nums.begin(), nums.end());
        reverse(nums.begin(), nums.begin() + k);
        reverse(nums.begin() + k, nums.end());
    }
};